package com.gjx.springboot.api.controller;

import com.gjx.springboot.domain.entity.Employees;
import com.gjx.springboot.domain.entity.User;
import com.gjx.springboot.app.service.EmployeesService;
import com.gjx.springboot.app.service.GjxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class GjxController {
    @Autowired
    GjxService gjxService;
    @Resource
    EmployeesService employeesService;
    @RequestMapping("/togjx")
    public String toGjx() {
        return "gjx";
    }

    @GetMapping("/getid")
    @ResponseBody
    public ResponseEntity<?> getId(int a) {
//        return a * 100;
        return ResponseEntity.ok(a*100);
    }

    @PostMapping("/getuser")
    @ResponseBody
    public String getUser(@RequestBody User user) {
        String name = user.getName();
        String sex = user.getSex();
        String age = user.getAge();
        sex = sex + "性";
        age = age + "周岁";
        String s = name + sex + age;
        return s;
    }

    @PutMapping("/getmark")
    @ResponseBody
    public User getMark(@RequestBody User user) {
        user.setMark("已经成年");
        return user;
    }

    @DeleteMapping("/deleteone")
    @ResponseBody
    public String deleteOne(@RequestBody User user) {
        return "张三已经删除";
    }


    //查询employees中的所有数据
    @RequestMapping("/getallemployees")
    @ResponseBody
    public List<Employees> getAll(){
        List<Employees> allEmployees = employeesService.getAllEmployees();
        return allEmployees;
    }
}
